package master;

import java.util.List;

/**
 *
 * 旋转链表
 *
 * @author chenyw
 * @date 2022/7/28 16:33
 */
public class M61rotateRight {
    public static void main(String[] args) {
        System.out.println(2 % 5);
    }
    public ListNode rotateRight(ListNode head, int k) {
        int count = 0;
        ListNode p = head;
        while (p != null) {
            p = p.next;
            count++;
        }
        if (count == 0 || count == 1) {
            return head;
        }
        k = k % count;
        if (k == 0) {
            return head;
        }
        System.out.println(k);
        System.out.println(count);
        count = 0;
        ListNode pre = head;
        p = head;
        ListNode q = head;
        while (p != null) {
            pre = p;
            p = p.next;
            //大于等于
            if (count >= k + 1) {
                q = q.next;
            }
            count++;
        }
        ListNode res = q.next;
        q.next = null;
        pre.next = head;
        return res;
    }
}
